<!DOCTYPE html>
<html>

<head>
    <title>Text Abbreviator</title>
    <meta charset="utf-8" />
</head>

<body>
<form method="get" action="task1.php">
    List (JSON): <textarea name="list" rows="15" cols="75">
        Java is an object-oriented programming language.
        PHP is a server-side scripting language.&#32;&#32;
        HTML is the standard markup language used to create web pages.

        To define a table in HTML use &lt;table&gt;, &lt;td&gt; and &lt;tr&gt; tags.</textarea> <br/>
    <input type="text" name="maxSize" value="50" />
    <input type="submit" value="Send" />
</form>
<?php
if (isset($_GET['list']) && isset($_GET['maxSize'])) {
    //$text = explode('\n', htmlspecialchars($_GET['list']));
    $text = preg_split("/((\r?\n)|(\r\n?))/", $_GET['list']);
    $size = $_GET['maxSize'];

    $result = "<ul>";

    foreach ($text as $line) {
        if ($line !== "") {
            $trimmedLine = preg_replace("/\s+/", " ", $line);
            $trimmedLine = trim($trimmedLine);

            if (strlen($trimmedLine) > $size) {
                $trimmedLine = substr($trimmedLine, 0, $size) . '...';
                $result .= "<li>" . htmlspecialchars($trimmedLine) . "</li>";
            }
            else {
                $result .= "<li>" . htmlspecialchars($trimmedLine) . "</li>";
            }
        }
    }

    $result .= "</ul>";

    echo $result;
}
?>
</body>

</html>



